# # make main.hex

# # Compilation chain
# CC = sdcc
# # Compile and generate directory
# BUILD_DIR = build/

# # Header file path
# INC_DIR = inc

# # Target file
# IHX = $(BUILD_DIR)main.ihx
# HEX = $(BUILD_DIR)main.hex

# # source file
# src_main = main.c
# src_delay = src/delay.c
# src_led = src/led.c

# # build rel file
# main_rel = $(BUILD_DIR)main.rel
# delay_rel = $(BUILD_DIR)deley.rel
# led_rel = $(BUILD_DIR)led.rel



# # 将.ihx文件转换为.hex文件
# $(HEX): $(IHX)
# 	packihx $(IHX) > $(HEX)

# # 规则：编译.c文件为.ihx文件
# $(IHX): $(main_rel) $(delay_rel) $(led_rel)
# 	$(CC) $(main_rel) $(delay_rel) $(led_rel) -o $(IHX)


# $(main_rel): $(src_main)
# 	$(CC) -c $(src_main) -I$(INC_DIR) -o $(main_rel)

# $(delay_rel): $(src_delay)
# 	$(CC) -c $(src_delay) -I$(INC_DIR) -o $(delay_rel)

# $(led_rel): $(src_led)
# 	$(CC) -c $(src_led) -I$(INC_DIR) -o $(led_rel)

# # 默认目标：编译主程序并转换为.hex
# all: $(HEX)

# init:
# 	mkdir -p $(dir $(IHX))

# # 清理目标文件
# clean:
# 	rm -f $(BUILD_DIR)*
# 	ls $(dir $(HEX)) 




##########################################



# Compilation chain
CC = sdcc
BUILD_DIR = build/
INC_DIR = inc

# Source files and corresponding object files
# SRC_FILES := \
# 	main.c \
# 	src/delay.c \
# 	src/led.c \
# 	src/beep.c \
# 	src/nixie_tube.c\

SRC_FILES := main.c
# 获取src所有源文件（.c）
SRC_FILES += $(wildcard src/*.c)
# SRC_FILES := \
# 	main.c \
# 	src/*.c \


OBJ_FILES := $(patsubst %.c,$(BUILD_DIR)%.rel,$(SRC_FILES))
# Target files
IHX := $(BUILD_DIR)main.ihx
HEX := $(BUILD_DIR)main.hex

# 将.ihx文件转换为.hex文件
%.hex: %.ihx
	packihx %.ihx > %.hex

# # 编译和链接规则
# $(IHX): $(OBJ_FILES)
#     $(CC) $(OBJ_FILES) -o $(IHX)

%.ihx: %.rel
	$(CC) %.rel -o %.ihx



$(BUILD_DIR)%.rel: %.c
	$(CC) -c $< -I$(INC_DIR) -o $@


# # 编译和链接规则
$(HEX): $(IHX)
	packihx $(IHX) > $(HEX)

# # # 编译和链接规则
$(IHX): $(OBJ_FILES)
	$(CC) $(OBJ_FILES) -o $(IHX)

rel: $(OBJ_FILES) 


hex:$(HEX)

all:$(HEX)

init:
	mkdir -p $(dir $(IHX))
	mkdir -p $(dir ./build/src/led.rel)

# # 清理目标文件
clean:
	rm -rf $(BUILD_DIR)*
	mkdir -p $(dir ./build/src/led.rel)
	ls $(dir $(HEX)) 
